package com.shop.front.service.store;

import com.shop.front.vo.store.StoreProductVo;
import com.shop.domain.store.StoreProductAttr;
import com.shop.domain.store.StoreProductAttrValue;
import com.shop.domain.store.StoreProductDescription;
import com.shop.front.dao.store.*;
import com.shop.front.request.store.StoreProductReq;
import com.shop.web.context.WebContext;
import com.shop.web.response.BaseResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Slf4j
@Transactional
public class StoreProductService {

    @Autowired
    private StoreProductDao storeProductDao;
    @Autowired
    private StoreProductSQLDao storeProductSQLDao;
    @Autowired
    private StoreProductDescriptionDao storeProductDescriptionDao;
    @Autowired
    private StoreProductAttrDao storeProductAttrDao;
    @Autowired
    private StoreProductAttrValueDao storeProductAttrValueDao;

    public StoreProductVo findVoById(Long id) {
        return storeProductSQLDao.findVoById(id);
    }

    public StoreProductDescription findDescriptionByProductId(Long productId) {
        return storeProductDescriptionDao.findByProductId(productId);
    }

    public List<StoreProductVo> list(Integer rowNum, StoreProductReq req) {
        WebContext.setPageSize(rowNum);
        return storeProductSQLDao.page(req).getContent();
    }

    public BaseResponse page(StoreProductReq req) {
        Page<StoreProductVo> page = storeProductSQLDao.page(req);
        return new BaseResponse(page);
    }

    public List<StoreProductAttr> productAttr(Long productId) {
        return storeProductAttrDao.findByProductIdOrderByIdAsc(productId);
    }

    public StoreProductAttrValue productAttrValue(Long productId, String suk) {
        return storeProductAttrValueDao.findByProductIdAndSuk(productId, suk);
    }
}
